class Solution {
public:
    int n;
    vector<vector<int>> ans;
    vector<int> path;
    void dfs(vector<vector<int>>& graph, int u)
    {
        path.push_back(u);
        if(u==n-1) ans.push_back(path);
        for(int v:graph[u])
        {
            dfs(graph, v);
        }
        path.pop_back();
    }

    vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
        n=graph.size();
        dfs(graph, 0);
        return ans;
    }
};